from rest_framework import serializers

from bugs.models import Bug, BugHandle
from interfaces.models import Interface
from projects.models import Project


class BugSerializer(serializers.ModelSerializer):
    project = serializers.PrimaryKeyRelatedField(queryset=Project.objects.all().filter(is_deleted=False))
    interface = serializers.PrimaryKeyRelatedField(queryset=Interface.objects.all().filter(is_deleted=False))
    interface_url = serializers.CharField(read_only=True, source='interface.url')
    # user = serializers.CharField(read_only=True, source='user.username')
    user = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = Bug
        exclude = ['is_deleted']  # noqa


class BugHandleSerializer(serializers.ModelSerializer):
    bug = serializers.PrimaryKeyRelatedField(queryset=Bug.objects.all().filter(is_deleted=False))
    # user = serializers.CharField(read_only=True, source='user.username')
    update_user = serializers.StringRelatedField(read_only=True)

    class Meta:
        model = BugHandle
        fields = '__all__'
